package cn.itcast.java.map;

import cn.itcast.java.list.ListDemo02;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Author itcast
 * Date 2021/10/10 17:40
 * HashMap 存储格式：
 * key -> value
 * zs -> 1
 * ls -> 2
 * wangwu -> 3
 */
public class MapDemo01 {
    public static void main(String[] args) {
        //创建 map 类
        Map<String,Integer> students = new HashMap<>();
        //添加3个值
        students.put("zs",1);
        students.put("ls",2);
        students.put("wangwu",3);
        //打印输出3个值
        Collection<Integer> values = students.values();
        for (Integer value : values) {
            System.out.println(value);
        }

        //remove 元素
        Integer wangwu = students.remove("wangwu");
        System.out.println(wangwu);
        for (String s : students.keySet()) {
            System.out.println("姓名:"+s+" 年龄："+students.get(s));
        }
        //containsKey(key)
        boolean flag = students.containsKey("zs");
        System.out.println("是否包含张三："+flag);

        Map<String, ListDemo02.Student> maps = new HashMap<>();
        maps.put("100001",new ListDemo02.Student("zhangsan",20));
        for (String key : maps.keySet()) {
            System.out.println(maps.get(key));
        }
    }
}
